<!DOCTYPE HTML>
<html>
	<body>
		<p>计数：<output id="result"></output></p>
		<button onclick="startWorker()">开始 Worker</button>
		<button onclick="stopWorker()">停止 Worker</button>

		<script type="text/javascript">
            var work;
            //开始
          window.onload =  function startWorker(){
            	if(typeof(Worker)!=="undefined"){
            		if(typeof(work)=="undefined"){
            			work = new Worker("./demo_workers.js");
            		}

            		work.onmessage = function (event){
                        document.getElementById('result').innerHTML = event.data;
            		}
            	}else{
            		document.getElementById('result').innerHTML = "抱歉，您的浏览器不支持 Web Store....";
            	}
            }

            //停止
            function stopWorker(){
            	work.terminate();
            }

		</script>

	</body>
</html>